home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / zht1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-29  |  4.4 KB  |  144 lines

  1. /* Copyright (C) 1994, 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* zht1.c */
  20. /* setcolorscreen operator */
  21. #include "ghost.h"
  22. #include "memory_.h"
  23. #include "errors.h"
  24. #include "oper.h"
  25. #include "estack.h"
  26. #include "gsstruct.h"            /* must precede igstate.h, */
  27.                     /* because of #ifdef in gsht.h */
  28. #include "ialloc.h"
  29. #include "igstate.h"
  30. #include "gsmatrix.h"
  31. #include "gxdevice.h"            /* for gzht.h */
  32. #include "gzht.h"
  33. #include "gsstate.h"
  34. #include "iht.h"
  35. #include "store.h"
  36.  
  37. /* Dummy spot function */
  38. float
  39. spot_dummy(floatp x, floatp y)
  40. {    return (x + y) / 2;
  41. }
  42.  
  43. /* <red_freq> ... <gray_proc> setcolorscreen - */
  44. private int setcolorscreen_finish(P1(os_ptr));
  45. private int setcolorscreen_cleanup(P1(os_ptr));
  46. private int
  47. zsetcolorscreen(register os_ptr op)
  48. {    gs_colorscreen_halftone cscreen;
  49.     ref sprocs[4];
  50.     gs_halftone *pht;
  51.     gx_device_halftone *pdht;
  52.     int i;
  53.     int code = 0;
  54.     int space = 0;
  55.     gs_memory_t *mem;
  56.  
  57.     for ( i = 0; i < 4; i++ )
  58.       {    os_ptr op1 = op - 9 + i * 3;
  59.         int code = zscreen_params(op1, &cscreen.screens.indexed[i]);
  60.         if ( code < 0 )
  61.           return code;
  62.         cscreen.screens.indexed[i].spot_function = spot_dummy;
  63.         sprocs[i] = *op1;
  64.         space = max(space, r_space_index(op1));
  65.       }
  66.     mem = (gs_memory_t *)idmemory->spaces.indexed[space];
  67.     check_estack(8);        /* for sampling screens */
  68.     rc_alloc_struct_0(pht, gs_halftone, &st_halftone,
  69.               mem, pht = 0, "setcolorscreen(halftone)");
  70.     rc_alloc_struct_0(pdht, gx_device_halftone, &st_device_halftone,
  71.               mem, pdht = 0, "setcolorscreen(device halftone)");
  72.     if ( pht == 0 || pdht == 0 )
  73.       code = gs_note_error(e_VMerror);
  74.     else
  75.       {    pht->type = ht_type_colorscreen;
  76.         pht->params.colorscreen = cscreen;
  77.         code = gs_sethalftone_prepare(igs, pht, pdht);
  78.       }
  79.     if ( code >= 0 )
  80.       {    /* Schedule the sampling of the screens. */
  81.         es_ptr esp0 = esp;        /* for backing out */
  82.         esp += 8;
  83.         make_mark_estack(esp - 7, es_other, setcolorscreen_cleanup);
  84.         memcpy(esp - 6, sprocs, sizeof(ref) * 4);    /* procs */
  85.         make_istruct(esp - 2, 0, pht);
  86.         make_istruct(esp - 1, 0, pdht);
  87.         make_op_estack(esp, setcolorscreen_finish);
  88.         for ( i = 0; i < 4; i++ )
  89.         {    /* Shuffle the indices to correspond to */
  90.             /* the component order. */
  91.             code = zscreen_enum_init(op,
  92.                 &pdht->components[(i + 1) & 3].corder,
  93.                 &pht->params.colorscreen.screens.indexed[i],
  94.                 &sprocs[i], 0, 0, mem);
  95.             if ( code < 0 )
  96.             {    esp = esp0;
  97.                 break;
  98.             }
  99.         }
  100.     }
  101.     if ( code < 0 )
  102.       {    gs_free_object(mem, pdht, "setcolorscreen(device halftone)");
  103.         gs_free_object(mem, pht, "setcolorscreen(halftone)");
  104.         return code;
  105.       }
  106.     pop(12);
  107.     return o_push_estack;
  108. }
  109. /* Install the color screen after sampling. */
  110. private int
  111. setcolorscreen_finish(os_ptr op)
  112. {    gx_device_halftone *pdht = r_ptr(esp, gx_device_halftone);
  113.     int code;
  114.     pdht->order = pdht->components[0].corder;
  115.     code = gx_ht_install(igs, r_ptr(esp - 1, gs_halftone), pdht);
  116.     if ( code < 0 )
  117.         return code;
  118.     memcpy(istate->screen_procs.indexed, esp - 5, sizeof(ref) * 4);
  119.     make_null(&istate->halftone);
  120.     esp -= 7;
  121.     setcolorscreen_cleanup(op);
  122.     return o_pop_estack;
  123. }
  124. /* Clean up after installing the color screen. */
  125. private int
  126. setcolorscreen_cleanup(os_ptr op)
  127. {    gs_halftone *pht = r_ptr(esp + 6, gs_halftone);
  128.     gx_device_halftone *pdht = r_ptr(esp + 7, gx_device_halftone);
  129.  
  130.     gs_free_object(pdht->rc.memory, pdht,
  131.                "setcolorscreen_cleanup(device halftone)");
  132.     gs_free_object(pht->rc.memory, pht,
  133.                "setcolorscreen_cleanup(halftone)");
  134.     return 0;
  135. }
  136.  
  137. /* ------ Initialization procedure ------ */
  138.  
  139. BEGIN_OP_DEFS(zht1_op_defs) {
  140.     {"<setcolorscreen", zsetcolorscreen},
  141.         /* Internal operators */
  142.     {"0%setcolorscreen_finish", setcolorscreen_finish},
  143. END_OP_DEFS(0) }
  144.